<%-- 
    Document   : queryInfo
    Created on : 2017-3-24, 10:15:04
    Author     : 52461
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include file="../../link.jsp"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>质控物管理</title>
        <style>
            .form-control{
                width: 100px;
            }
        </style>
    </head>
    <body ng-app="zkObjectApp" ng-controller="mainCtrl" style="overflow: hidden;margin-top: 5px;">
        <div class="col-lg-12">
            <div class="panel panel-default" style="overflow: hidden">

                <div class="panel-heading head-width"><span style="float: left;line-height: 30px;font-size: 16px; font-weight: bold;margin-right: 10px;">质控物管理</span>
                    <div class="form-inline">

                        <div class="form-group">
                            <label for="startTime">设备:</label>
                            <select ng-model="device" ng-change="getZkDeviceItem()" style="width:120px" class="form-control" id="startTime">
                                <option ng-repeat="de in des" value="{{de.DEVICEMODEL}}">{{de.DEVICEMODEL}}</option>
                            </select>
                        </div>
                        <button ng-disabled="!device" ng-click="openAddZkItemModal()" class="btn btn-success "><span class="fa fa-plus-square"></span>&nbsp;&nbsp;&nbsp;添加</button>
                        <!--<button ng-click="printResult()" class="btn btn-success btn-sm"><span class="fa fa-print"></span>&nbsp;&nbsp;&nbsp;打印</button>-->
                    </div>


                    <div style="clear: both"></div>
                </div>

                <table  style="width:100%">


                    <tr>
                        <td  class="main-left" valign="top" style="overflow: auto">
                            <div class=" main main-left" style="overflow: auto;width: 100%"  >
                                <table class="table table-bordered ">
                                    <tr>
                                        <th style="width:50px;">序号</th>
                                        <th>缩写</th>
                                        <th>名称</th>
                                        <th>质控规则</th>
                                        <th>失控规则</th>                                      
                                        <th>其他</th>
                                    </tr>
                                    <tr ng-repeat="list in zkDeviceData" >
                                        <td style="width:50px;" ng-bind="$index" ></td>
                                        <td ng-bind="list.TESTID"></td>
                                        <td ng-bind="list.CHINESENAME"></td>
                                        <td ng-bind="list.ZK_RULE"></td>
                                        <td>
                                            <div style="padding:.2em .6em .3em;float: left "  ng-repeat="item in list.SK_RULE"><span class="label label-success" ng-bind="item"></span></div>
                                        </td>                                    

                                        <td>
                                            <button class="btn btn-danger btn-xs" ng-click="deleteItem(list)" ><span class="fa fa-close"></span>删除</button>
                                        </td>
                                    </tr>
                                </table>
                            </div>

                        </td>




                    </tr>

                    </tbody>
                </table>


            </div>

        </div>


        <div class="modal fade add-item " tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" id="myModal">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close" ng-click="deteleInfo()"><span aria-hidden="true">&times;</span></button>
                        <h3 class="modal-title" style="text-align:center ; font-weight: bold;font-size: 20px">添加质控项目</h3>
                    </div>
                    <div class="modal-body add-zk-object" style="overflow: auto">
                        <table class="table table-bordered">
                            <tr>
                                <th></th>
                                <th>编号</th>
                                <th>项目缩写</th>
                                <th>项目名称</th>

                            </tr>
                            <tr ng-repeat="item in deviceData">
                                <td>
                                    <input ng-disabled="item.disable" ng-model="item.check" type="checkbox"  >
                                </td>
                                <td ng-bind="$index">
                                </td>
                                <td ng-bind="item.TESTID">
                                </td>
                                <td ng-bind="item.CHINESENAME">
                                </td>
                            </tr>
                        </table>
                    </div>
                    <div class="modal-footer" >
                        <button type="button" class="btn btn-default" data-dismiss="modal" ng-click="deteleInfo()">取消</button>
                        <button type="button" class="btn btn-primary" ng-click="saveItem()" >保存</button>

                    </div>
                </div>
            </div>

        </div>
    </body>
</html>
<script>
    angular.module("zkObjectApp", ['baseModule', 'ui.bootstrap'])

            .controller("mainCtrl", function ($scope, base) {

                $scope.getDeviceType = function () {
                    base.post("${base}/view/host/getType").get(function (data) {
                        $scope.des = data;
                    });
                };
                $scope.openAddZkItemModal = function () {
                    $scope.getDeviceItem();
                    $(".add-item").modal("show");
                }
                $scope.getDeviceItem = function () {
                    base.post("zk_object/getDeviceItem", {device: $scope.device}).get(function (data) {

                        $scope.deviceData = data;

                        for (var i = 0; i < $scope.zkDeviceData.length; i++) {

                            for (var j = 0; j < $scope.deviceData.length; j++) {

                                if ($scope.deviceData[j].TESTID == $scope.zkDeviceData[i].TESTID) {

                                    $scope.deviceData[j].check = true;
                                    $scope.deviceData[j].disable = true;
                                }
                            }
                        }

                    });
                };
                $scope.getZkDeviceItem = function () {
                    base.post("zk_object/getZkDeviceItem", {device: $scope.device}).get(function (data) {

                        $scope.zkDeviceData = data;
                        if ($scope.zkDeviceData) {
                            for (var i = 0; i < $scope.zkDeviceData.length; i++) {

                                if ($scope.zkDeviceData[i].ZK_RULE == "1") {
                                    $scope.zkDeviceData[i].ZK_RULE = "westgard 多规则";
                                }
                                if ($scope.zkDeviceData[i].SK_RULE) {
                                    $scope.zkDeviceData[i].SK_RULE = $scope.zkDeviceData[i].SK_RULE.split(",");
                                }
                            }

                        }
                    });
                }
                $scope.deleteItem = function (item) {
                    base.post("zk_object/deleteItem", {pk: item.PK}).get(function (data) {
                        if (data == 'true') {
                            steveAl("删除成功", 1000);
                            $scope.getZkDeviceItem();
                        }
                    })
                }
                $scope.saveItem = function () {
                    var saveItemArray = [];

                    for (var i = 0; i < $scope.deviceData.length; i++) {
                        if (!$scope.deviceData[i].disable && $scope.deviceData[i].check) {
                            saveItemArray.push($scope.deviceData[i]);
                        }
                    }
                    if (saveItemArray.length > 0) {
                        saveItemToServer(saveItemArray);
                    } else {
                        steveAl("无保存数据");
                    }
                }
                var saveItemToServer = function (data) {
                    base.post("zk_object/saveZkItem", {data: angular.toJson(data)}).get(function (data) {
                        if (data == 'true') {
                            steveAl("保存成功", 1000);
                            $scope.getZkDeviceItem();
                        } else {
                            steveAl("保存失败", 1000);
                        }
                        $(".add-item").modal("hide");
                    })
                }

                //$scope.queryInfo();
                $scope.getDeviceType();




            });





    function autoHeight() {
        var bHeight = $(window).height();
        var bWidth = $(window).width();

        $(".main").height(bHeight - $(".head-width").height() - 75);
        $(".add-zk-object").height(bHeight - $(".head-width").height() - 175);


    }
    autoHeight();


    $(window).resize(function () {
        autoHeight();
    });
</script>
